﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XCommunity.Frames;
using XCommunity.Web;
using XCommunity.Members;
using System.Drawing;
using XCommunity.Views;
using Ivony.Web.WebControls;
using XCommunity.Web.UI;
using XCommunity.Users;
using XCommunity;
using XCommunity.Forums.Views;

public partial class Forums_Presenters_PostFramePresenter : System.Web.UI.UserControl, ICallbackEventHandler
{

  public GeneralPostFrameView ViewObject
  {
    get
    {
      return (GeneralPostFrameView) this.GetView();
    }
  }


  protected void Page_Load( object sender, EventArgs e )
  {

    DataBind();

    Actions.Controls.Add( new HyperLink() { Text = "回应", NavigateUrl = "javascript:window.alert( '此功能暂未开放' );" } );


    Permission permission = ( (ICommunitySystem) WebCommunityContext.Current.ForumsSystem ).UserService.GetUserPermissions();


    if ( permission.GetControl( "ModifyPost", ViewObject.PostFrame, ViewObject.PostFrame.Topic ) == ControlType.Allow )
      Actions.Controls.Add( new HyperLink() { Text = "修改", NavigateUrl = string.Format( "~/ModifyPost.aspx?topic={0}&post={1}&source={2}", ViewObject.TopicId, ViewObject.PostId.ToString( "N" ), HttpUtility.UrlEncode( Request.Url.ToString() ) ) } );

    if ( permission.GetControl( "DeletePost", ViewObject.PostFrame, ViewObject.PostFrame.Topic ) == ControlType.Allow )
      Actions.Controls.Add( new HyperLink() { Text = "删除", Target = "_blank", NavigateUrl = "javascript:window.alert( '此功能暂未开放' );" } );


    if ( ViewObject.IsModified )
      PublishInfo.Controls.Add( new LiteralControl( string.Format( "<a href=\"javascript:ShowHistoricalView( '{2:n}', {3} );\" title=\"查看历史版本\" style=\"color: #0033CC;\">{0} 于 {1:yyyy-MM-dd HH:mm} 修改</a>", ViewObject.CurrentVersion.Author, ViewObject.CurrentVersion.PublishDate, ViewObject.PostId, ViewObject.CurrentVersion.DocumentId ) ) );
    else
      PublishInfo.Controls.Add( new LiteralControl( string.Format( "<span style=\"color: #999999;\">{0} 于 {1:yyyy-MM-dd HH:mm} 发布</span>", ViewObject.CurrentVersion.Author, ViewObject.CurrentVersion.PublishDate ) ) );


    UserActions.Controls.Add( new HyperLink() { Text = "顶(0)", NavigateUrl = "javascript:window.alert( '此功能暂未开放' )", ToolTip = "绝世好帖，兄弟们给我顶！" } );
    UserActions.Controls.Add( new HyperLink() { Text = "踩(0)", NavigateUrl = "javascript:window.alert( '此功能暂未开放' )", ToolTip = "满嘴喷粪，大家一起踩！" } );
    UserActions.Controls.Add( new HyperLink() { Text = "阅(0)", NavigateUrl = "javascript:window.alert( '此功能暂未开放' )", ToolTip = "大爷已阅。。" } );

  }

  protected Member GetMember()
  {
    return WebCommunityContext.CurrentCommunityContext.MemberService.GetMember( ViewObject.Author );
  }

  protected void VersionItemDataBound( object sender, RepeaterItemEventArgs e )
  {
    var docuemnt = ( (PublishedDocumentView) e.Item.DataItem ).Document;

    if ( string.IsNullOrEmpty( docuemnt.Meta.Caption ) )
      e.Item.FindControl( "DocumentTitle" ).Controls.Add( new Label() { Text = "<无标题文档>", ForeColor = Color.FromArgb( 0x999999 ) } );
    else
      e.Item.FindControl( "DocumentTitle" ).Controls.Add( new LiteralControl( HttpUtility.HtmlEncode( docuemnt.Meta.Caption ) ) );

    e.Item.FindControl( "DocumentContent" ).Controls.Add( new DocumentContentPresenter( docuemnt, WebCommunityContext.Current.GetDefaultDocumentProvider() ) );

  }

  #region ICallbackEventHandler 成员

  public string GetCallbackResult()
  {
    return ViewObject.PostId + "," + "assent" + "," + 5;
  }

  public void RaiseCallbackEvent( string eventArgument )
  {

  }

  #endregion
}
